package team.seekers.catering.config.service.impl;

import team.seekers.catering.common.enums.ConfigTypeEnum;
import team.seekers.catering.common.enums.FoodPackageTypeEnum;
import team.seekers.catering.config.entity.Config;
import team.seekers.catering.config.mapper.ConfigMapper;
import team.seekers.catering.config.service.ConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 配置表 服务实现类
 * </p>
 *
 * @author hbc
 * @since 2022-03-01
 */
@Service
public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> implements ConfigService {

    @Override
    public Integer getPackageOrderNumber(FoodPackageTypeEnum type) {
        Config config = getById(ConfigTypeEnum.PACKAGE_ORDER_NUMBER.getType()+""+type.getValue());
        return Integer.parseInt(config.getValue());
    }

    @Override
    public void addPackageOrderNumber(FoodPackageTypeEnum type) {
        Config config = getById(ConfigTypeEnum.PACKAGE_ORDER_NUMBER.getType()+""+type.getValue());
        Integer number = Integer.parseInt(config.getValue()) + 1;
        config.setValue(number.toString());
        updateById(config);
    }
}
